<title>企业信息列表</title>
<!-- /section:settings.box -->
<div class="row enterprise_list">
	<div class="col-xs-12">
		<div class="ad_so">
			<input type="text" id="firm_name" class="input-large"
				placeholder="企业名称">
			<button type="button" class="btn btn-info serach">
				<i class="glyphicon glyphicon-search"> </i> 搜索
			</button>
		</div>
		<div class="tabbable tabbable2">
			<ul class="nav nav-tabs padding-12 tab-color-blue background-blue">
				<li name="li_tab" class="active" data-identity="-1"><a
					href="javascript:;"> 全部 </a></li>
			</ul>
		</div>
		<div class="row">
			<div class="col-xs-12">
				<div>
					<table class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th>ID</th>
								<th>编号</th>
								<th>被处罚人(单位)</th>
								<th>处罚类型</th>
								<th>处罚时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody class="data" style="display: table-row-group;">
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="pull-left">
			<button type="button" class="btn btn-info add" data-identity="add"
				title="新增">
				<i class="ace-icon glyphicon glyphicon-plus"> </i>新增
			</button>
		</div>
		<!--分页-->
		<nav class="pull-right">
			<ul class="pagination">
				<li><a class="first" href="javascript:void(1);"
					aria-label="Previous"> 首页 </a></li>
				<li><a class="prev" href="javascript:void(1);"> <i
						class="ace-icon fa fa-angle-double-left"> </i>上一页
				</a></li>
				<li><a class="next" href="javascript:void(1);"> 下一页 <i
						class="ace-icon fa fa-angle-double-right"> </i>
				</a></li>
				<li><a class="last" href="javascript:void(1);" aria-label="Next"> 尾页
				</a></li>
				<li><a class="go_page" href="javascript:void(1);"> 跳转到 </a></li>
				<li><input type="text" style="width: 30px" class="go_num" value="1">
				</li>
				<li>页</li>
			</ul>
		</nav>
		<!-- TemplteHidden -->
		<table class="list-tpl hidden">
			<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td>
					<button type="button" class="btn btn-mini btn-success detail"
						data-identity="detail" title="查看详情">
						<i class="ace-icon glyphicon glyphicon-eye-open"> 详情</i>
					</button>
					<button type="button" class="btn btn-mini btn-info edit"
						data-identity="edit" title="修改">
						<i class="ace-icon glyphicon glyphicon-edit"> 修改</i>
					</button>
					<button type="button" class="btn btn-mini btn-danger delete"
						data-identity="del" title="删除">
						<i class="ace-icon glyphicon glyphicon-trash"> 删除</i>
					</button>
				</td>
			</tr>
		</table>
		<!--  TemplteHidden  -->
	</div>
</div>
<script type="text/javascript">var scripts = [null,
	null
];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	var $scope = $('.enterprise_list');
	function pageInit(page) {
		$.getJSON(page.url, {
				page: page.pi
			},
			function(ret) {
				if (ret.status == 200) {
					var $data = $('.data', $scope);
					$data.hide();
					$data.empty();
					var data = ret.data;
					pageObj.set_page_count_without_action(ret.page_count);
					$("li[name='li_tab'][data-identity='-1']>a", $scope).text("全部（" + ret.tct + "）");
					for (var i in data) {
						var v = data[i];
						var id = v['id'];
						var $item = $('.list-tpl tr', $scope).clone();
						$('td:eq(0)', $item).text(id);
						$('td:eq(1)', $item).text(v['auto_no']);
						$('td:eq(2)', $item).text(v['be_punished_man']);
						$('td:eq(3)', $item).text(v['category_str']);
						$('td:eq(4)', $item).text(v['add_time']);
						$('td:eq(5) .detail', $item).attr('data-identity', 'detail-' + id);
						$('td:eq(5) .edit', $item).attr('data-identity', 'edit-' + id);
						$('td:eq(5) .delete', $item).attr('data-identity', 'delete-' + id);
						$data.append($item);
					} //对应字符的输入框位
					$data.show();
				} else {
					pageObj.set_page_count_without_action(1);
					message_box.show(ret.data, 'error');
				}
			});
	}
	pageObj = new pagination({
		'url': '/administrative/ajax_administrative_list'+ create_where(),
		'page_count': 9,
		'show_callback': function(page) {
			pageInit(page);
		}
	});
	$('.first', $scope).click(function() {
		pageObj.first_page();
		$('.go_num', $scope).val('1');
	});
	$('.prev', $scope).click(function() {
		pageObj.prev_page();
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	$('.next', $scope).click(function() {
		pageObj.next_page();
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	$('.last', $scope).click(function() {
		pageObj.last_page();
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	//跳转输入框
	$('.go_num', $scope).change(function() {
		var num = $(this).val();
		if (num > pageObj.get_page_count()) {
			$(this).val(pageObj.get_page_count());
		} else if (num < 1) {
			$(this).val(1);
		}
	})
	$('#serach').click(function() {
		var url = '/administrative/ajax_administrative_list' + create_where();
		pageObj = new pagination({
			'url': url,
			'page_count': 2,
			'show_callback': function(page) {
				pageInit(page);
			}
		});
	});
	//跳转至指定页面
	$('.go_page', $scope).click(function() {
		var num = $('.go_num', $scope).val();
		pageObj.go_page(num);
		$('.go_num', $scope).val(pageObj.get_page_index());
	});
	//在指定的范围内查找符合条件的元素，绑定事件，
	$scope.delegate('[data-identity="add"]', 'click', function() {
		var url = "/administrative/add?dialog=1&mid=<?=$master_id?>";
		gDialog.fCreate({
			title: '行政处罚-增加',
			url: url,
			width: 800
		}).show();
	}).delegate('[data-identity^="edit-"]', 'click', function() {
		var id = $(this).attr('data-identity').split('-')[1];
		var url = '/#administrative/editor?dialog=1&id='+id;
		location.href=url;
	}).delegate('[data-identity^="delete-"]', 'click', function() {
		var id = $(this).attr('data-identity').split('-')[1];
		var url = '/administrative/ajax_administrative_delete';
		gDialog.fConfirm('删除行政处罚', '你确定执行这个操作么？', function(ret) {
			if (ret) {
				$.post(url, {
					id: id
				}, function(ret) {
					if (ret.status = 200) {
						message_box.show('删除成功', 'success');
						pageObj.cur_page();
					} else {
						message_box.show(ret.data, 'error');
					}
				}, 'json');
			}
		});
	}).delegate('[data-identity^="detail-"]', 'click', function() {
		var id = $(this).attr('data-identity').split('-')[1];
		var url = '#administrative/detail?id=' + id;
		location.href=url;
	});

	function create_where() {
		var firm_name = $("#hx_firm_name", $scope).val() || "";
		var tb = $("li[name='li_tab'][class='active']", $scope).attr("data-identity");
		var where = "?id=<?=$master_id?>&fname=" + firm_name;
		return where;
	}
	$("li[name='li_tab']", $scope).click(function() {
		$("li[name='li_tab']").removeClass("active");
		$(this).addClass("active");
		url = '/administrative/ajax_administrative_list' + create_where();
		pageObj = new pagination({
			'url': url,
			'page_count': 9,
			'show_callback': function(page) {
				pageInit(page);
			}
		});
	});
	$('.serach').click(function() {
		var url = '/administrative/ajax_administrative_list' + create_where();
		pageObj = new pagination({
			'url': url,
			'page_count': 9,
			'show_callback': function(page) {
				pageInit(page);
			}
		});
	});
})</script>
